using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Collections;
using XYThreadPoolLib;
using System.Diagnostics;
using Magnolia;

namespace CommLayer
{
    class InputProcessorMedialonServer : InputProcessorMedialon
    {

        public byte m_prefix;
        public byte m_suffix;
        protected TcpIpServerMedialon m_parent;

        /// <summary>
        /// Constructor. Processes all the input, medialon protocol
        /// </summary>
        /// <param name="prefix"></param>
        /// <param name="suffix"></param>
        public InputProcessorMedialonServer(byte prefix, byte suffix,
                        StringInputHandlerDelegate delegateStringInputHandler,TcpIpServerMedialon parent)
            :
                base(prefix, suffix,delegateStringInputHandler,parent.ThreadPool)
        {
            Parent = parent;
        }

        /// <summary>
        /// Parent container of the input processor
        /// </summary>
        public TcpIpServerMedialon Parent
        {
            get
            {
                return m_parent;
            }
            set
            {
                m_parent = value;
            }
        }



        /// <summary>
        /// Overriable: remove transmission from list
        /// </summary>
        public override void EndInputProcessor(Transmission trn)
        {
            Parent.ReaddTransmission(trn);

        }

        /// <summary>
        /// Handle client exception
        /// </summary>
        public override void HandleException(Exception oBug, Transmission trn)
        {
            // trace from here too
            Trace.WriteLineIf(AppContext.AppTraceSwitch.TraceError, DateTime.Now.ToLongTimeString() + "-> InputProcessorMedialonServer.HandleException:" + oBug.Message);
            // and handle it
            Parent.HandleException(oBug,trn);
        }

    }
}
